﻿using ProjectCloth.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectCloth.FrmUI
{
    public partial class SubjectFrm : Form
    {
        private ClothContext db = new ClothContext();
        public SubjectFrm()
        {
            InitializeComponent();

        }
        public SubjectFrm(string name)
        {
            InitializeComponent();
        }
        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(nameTxt.Text))
            {
                MessageBox.Show("请输入名称！");
                return;
            }
            if (db.Subjects.Where(o => o.Name == nameTxt.Text).Count() > 0)
            {
                MessageBox.Show("该名称已经存在，请更换！");
                return;
            }
            var subject = new Subject()
            {
                Name = nameTxt.Text,
                Remark = remarkTxt.Text
            };
            db.Subjects.Add(subject);
            var result = db.SaveChanges();
            if (result > 0)
            {
                MessageBox.Show("添加成功！");
            }
        }
    }
}
